--[[
* MapLib 2.0
* File: <AddOn>\MapLib\MapLib.XML.lua
* $Revision: 140 $
* $Date: 2007-01-14 10:12:19 +0000 (Sun, 14 Jan 2007) $
* 
* Copyright (c) 2006-2007, Mery (Moritz Metelmann)
* All rights reserved.
* 
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* 
*    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*    * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]--

local vmajor, vminor = "MapLib-2.0", tonumber(string.sub("$Revision: 140 $", 12, -3))

-- Version check: Only one major instance of MapLib can be installed, if another already is: abort.
if (MapLib and MapLib.XML and (MapLib.XML.vmajor ~= vmajor or MapLib.XML.vminor >= vminor)) then return; end;

if (not MapLib) then MapLib = {}; end;
if (not MapLib.XML) then MapLib.XML = {}; end;
MapLib.XML.vmajor = vmajor;
MapLib.XML.vminor = vminor;

local L = MapLib.Localization;

MapLib.XML.CreateFrame = function()
	-- In case this is ever menat as an update function for a minor version this needs to change.
	if (MapLibFrame) then return; end;
	local frame = CreateFrame("Frame", "MapLibFrame");
	frame:SetFrameStrata("FULLSCREEN");
	frame:SetAllPoints(true);
	frame:EnableKeyboard(true);
	frame:Hide();
	local texture;
	-- Blackout World:
	-- Looks like this does not work, I dunno I'll leave it in.
	texture = frame:CreateTexture("MapLibBlackoutWorldTexture", "BACKGROUND");
	texture:SetTexture(0, 0, 0);
	texture:SetWidth(1024);
	texture:SetHeight(768);
	texture:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT");

	-- Background Artwork
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Top1");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", -512, 384);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Top2");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", -256, 384);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Top3");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", 0, 384);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Top4");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", 256, 384);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Middle1");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", -512, 128);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Middle2");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", -256, 128);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Middle3");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", 0, 128);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Middle4");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", 256, 128);	
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Bottom1");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", -512, -128);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Bottom2");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", -256, -128);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Bottom3");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", 0, -128);
	texture = frame:CreateTexture(nil, "ARTWORK");
	texture:SetTexture("Interface\\WorldMap\\UI-WorldMap-Bottom4");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", frame, "CENTER", 256, -128);		

	-- Title Font String
	local fontstring = frame:CreateFontString("MapLibTitleText", "ARTWORK");
	fontstring:SetFontObject(GameFontNormal);
	fontstring:SetText(L["World Map"]);
	fontstring:SetPoint("CENTER", frame, "CENTER", 0, 372);
	
	-- Positioning Guide
	local pg = CreateFrame("Frame", "MapLibPositioningGuide", frame);
	pg:SetWidth(1024);
	pg:SetHeight(768);
	pg:SetPoint("CENTER", frame, "CENTER", 0, 0);

	-- Top Anchor (in case Side Menu is open)
	local anchor = CreateFrame("Frame", "MapLibTopCenterAnchor", frame);
	anchor:SetWidth(1);
	anchor:SetHeight(1);
	anchor:SetPoint("TOP", pg, "TOP", 0, -69);
	
	-- Close button
	local button = CreateFrame("Button", "MapLibFrameCloseButton", frame);
	button:SetWidth(32);
	button:SetHeight(32);
	button:SetNormalTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Up");
	button:SetPushedTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Down");
	button:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight");
	button:SetPoint("TOPRIGHT", pg, "TOP", 516, 4);
	button:SetScript("OnClick", function() HideUIPanel(this:GetParent()); end);
	
	button = CreateFrame("Button", "MapLibFrameWindowedButton", frame);
	button:SetWidth(32);
	button:SetHeight(32);
	button:SetNormalTexture(MapLib.PATH.."\\Artwork\\Button-Windowed-Up");
	button:SetPushedTexture(MapLib.PATH.."\\Artwork\\Button-Windowed-Down");
	button:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight");
	button:SetPoint("TOPRIGHT", pg, "TOP", 495, 4);
	button:SetScript("OnClick", function() end);
	local texture = button:CreateTexture(nil, "BACKGROUND");
	texture:SetWidth(32);
	texture:SetHeight(32);
	texture:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Corner");
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", -4, -4);
	button:SetScript("OnClick", MapLib.WindowMode.Toggle);
	
	button = CreateFrame("Button", "MapLibFrameMinimizeButton", frame);
	button:SetWidth(32);
	button:SetHeight(32);
	button:SetNormalTexture(MapLib.PATH.."\\Artwork\\Button-Minimize-Up");
	button:SetPushedTexture(MapLib.PATH.."\\Artwork\\Button-Minimize-Down");
	button:SetDisabledTexture(MapLib.PATH.."\\Artwork\\Button-Minimize-Disabled");
	button:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight");
	button:SetPoint("TOPRIGHT", pg, "TOP", 474, 4);
	button:SetScript("OnClick", function() end);
	local texture = button:CreateTexture(nil, "BACKGROUND");
	texture:SetWidth(32);
	texture:SetHeight(32);
	texture:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Corner");
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", -4, -4);
	button:Disable(); -- Feature not yet in.
	button:Hide();

	button = CreateFrame("Button", "MapLibFrameLockButton", frame);
	button:SetWidth(32);
	button:SetHeight(32);
	button:SetNormalTexture(MapLib.PATH.."\\Artwork\\Button-Unlocked-Up");
	button:SetPushedTexture(MapLib.PATH.."\\Artwork\\Button-Unlocked-Down");
	button:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight");
	button:SetPoint("TOPRIGHT", pg, "TOP", 453, 4);
	button:SetScript("OnClick", function() end);
	local texture = button:CreateTexture(nil, "BACKGROUND");
	texture:SetWidth(32);
	texture:SetHeight(32);
	texture:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Corner");
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", -4, -4);
	button:Hide();
	button:SetScript("OnClick", function() MapLib.WindowMode.SetLocked(not MapLibSaved.WindowMode.locked); MapLibSaved.WindowMode.locked = not MapLibSaved.WindowMode.locked; end);
	
	button = CreateFrame("Button", "MapLibFrameSpeedButton", frame);
	button:SetWidth(32);
	button:SetHeight(32);
	button:SetNormalTexture(MapLib.PATH.."\\Artwork\\Button-Play-Up");
	button:SetPushedTexture(MapLib.PATH.."\\Artwork\\Button-Play-Down");
	button:SetDisabledTexture(MapLib.PATH.."\\Artwork\\Button-Play-Disabled");
	button:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight");
	button:SetPoint("TOPRIGHT", pg, "TOP", 431, 4);
	button:SetScript("OnClick", function() end);
	local texture = button:CreateTexture(nil, "BACKGROUND");
	texture:SetWidth(32);
	texture:SetHeight(32);
	texture:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Corner");
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", -4, -4);
	button:Disable(); -- Feature not yet in.
	button:Hide();
	
	-- Sizing Button
	button = CreateFrame("Button", "MapLibFrameSizingButton", frame);
	button:SetWidth(16);
	button:SetHeight(16);
	button:SetPoint("BOTTOMRIGHT", pg, "BOTTOMRIGHT");
	-- /script MapLibFrameSizingButton:SetPoint("BOTTOMRIGHT", MapLibPositioningGuide, "BOTTOMRIGHT", -2, 2);
	button:SetNormalTexture(MapLib.PATH.."\\Artwork\\Button-Sizing-Up");
	button:SetPushedTexture(MapLib.PATH.."\\Artwork\\Button-Sizing-Down");
--	button:SetDisabledTexture(MapLib.PATH.."\\Artwork\\Button-Play-Disabled");
	button:SetHighlightTexture(MapLib.PATH.."\\Artwork\\Button-Sizing-Highlight");
	local mouseOutsideScreen, newscale, start_x, start_y, topleft_x, topleft_y, m_anchor, m_relativeTo, m_relativePoint, m_xOffset, m_yOffset, stop_x, stop_y;
	button:SetScript("OnMouseDown", function() 
		start_x, start_y = GetCursorPosition();
		-- get the cursor position of the topleft corner, well i'll use the scale for that...
		scale = MapLibFrame:GetScale();
		topleft_x = start_x - 1024 * scale;
		topleft_y = start_y + 768 * scale;
		m_anchor, m_relativeTo, m_relativePoint, m_xOffset, m_yOffset = MapLibFrame:GetPoint();
		m_xOffset, m_yOffset = m_xOffset*scale, m_yOffset*scale;
--~ 		DevTools_Dump({GetCursorPosition()});
		MapLibFrameSizingButton:SetScript("OnUpdate", function()
			stop_x, stop_y = GetCursorPosition();
			newscale = math.min(math.max((stop_x - topleft_x)/1024, (topleft_y - stop_y)/768), math.min((1024 - topleft_x)/1024, (topleft_y - 0)/768));
			if (newscale < MapLib.WindowMode.MIN_SCALE) then newscale = MapLib.WindowMode.MIN_SCALE; end;
			MapLibFrame:SetScale(newscale);
			MapLibFrame:SetWidth(1024);
			MapLibFrame:SetHeight(768);	
			MapLibFrame:SetPoint(m_anchor, m_relativeTo, m_relativePoint, m_xOffset/newscale, m_yOffset/newscale);
		end);
	end);
	button:SetScript("OnMouseUp", function()
		MapLibFrameSizingButton:SetScript("OnUpdate", nil);
		stop_x, stop_y = GetCursorPosition();
		newscale = math.min(math.max((stop_x - topleft_x)/1024, (topleft_y - stop_y)/768), math.min((1024 - topleft_x)/1024, (topleft_y - 0)/768));
		if (newscale < MapLib.WindowMode.MIN_SCALE) then newscale = MapLib.WindowMode.MIN_SCALE; end;
		MapLibFrame:SetScale(newscale);
		MapLibFrame:SetWidth(1024);
		MapLibFrame:SetHeight(768);
		MapLibFrame:SetPoint(m_anchor, m_relativeTo, m_relativePoint, m_xOffset/newscale, m_yOffset/newscale);
		
		-- Save the new anchor + scale
		MapLibSaved.WindowMode.anchor = m_anchor;
		MapLibSaved.WindowMode.relativeTo = m_relativeTo;
		MapLibSaved.WindowMode.relativePoint = m_relativePoint;
		MapLibSaved.WindowMode.xOffset = m_xOffset/newscale;
		MapLibSaved.WindowMode.yOffset = m_yOffset/newscale;
		MapLibSaved.WindowMode.scale = newscale;
--~ 	DevTools_Dump({GetCursorPosition()});
	end);
	
	-- Detail Frame
	local df = CreateFrame("Frame", "MapLibDetailFrame", frame);
	df:Show();
	df:SetWidth(1002);
	df:SetHeight(668);
	df:SetPoint("TOPLEFT", pg, "TOP", -502, -69); -- How to move the detail frame LOL : /script MapLibDetailFrame:SetPoint("TOPLEFT", MapLibPositioningGuide, "TOP", -20, -69);
	
	-- Map Tiles
	texture = df:CreateTexture("MapLibDetailTile1", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", df, "TOPLEFT");
	texture = df:CreateTexture("MapLibDetailTile2", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile1", "TOPRIGHT");
	texture = df:CreateTexture("MapLibDetailTile3", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile2", "TOPRIGHT");
	texture = df:CreateTexture("MapLibDetailTile4", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile3", "TOPRIGHT");
	texture = df:CreateTexture("MapLibDetailTile5", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile1", "BOTTOMLEFT");
	texture = df:CreateTexture("MapLibDetailTile6", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile5", "TOPRIGHT");
	texture = df:CreateTexture("MapLibDetailTile7", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile6", "TOPRIGHT");
	texture = df:CreateTexture("MapLibDetailTile8", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile7", "TOPRIGHT");
	texture = df:CreateTexture("MapLibDetailTile9", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile5", "BOTTOMLEFT");
	texture = df:CreateTexture("MapLibDetailTile10", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile9", "TOPRIGHT");
	texture = df:CreateTexture("MapLibDetailTile11", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile10", "TOPRIGHT");
	texture = df:CreateTexture("MapLibDetailTile12", "BACKGROUND");
	texture:SetWidth(256);
	texture:SetHeight(256);
	texture:SetPoint("TOPLEFT", "MapLibDetailTile11", "TOPRIGHT");

	-- Highlight
	texture = df:CreateTexture("MapLibHighlight", "OVERLAY");
	texture:SetBlendMode("ADD");
	texture:Hide();
	texture:SetWidth(128);
	texture:SetHeight(128);
	texture:SetPoint("TOPLEFT", df, "TOPLEFT");
	
	-- WorldMap Button (players have this button as parent)
	button = CreateFrame("Button", "MapLibButton", frame);
	button:SetWidth(1002);
	button:SetHeight(668);
	button:SetPoint("TOPLEFT", df, "TOPLEFT", 0, 0);

	-- Area Labels
	local areaFrame = CreateFrame("Frame", "MapFrameAreaFrame", button);
	areaFrame:SetWidth(400);
	areaFrame:SetHeight(128);
	areaFrame:SetPoint("TOP", anchor, "TOP", 0, -10);
	fontstring = areaFrame:CreateFontString("MapLibFrameAreaLabel", "OVERLAY");
--~ 	fontstring:SetFontObject(WorldMapTextFont);
	fontstring:SetFont("Fonts\\FRIZQT__.TTF", 32, "OUTLINE, THICKOUTLINE");
	fontstring:SetTextColor(1.0, 0.9294, 0.7607);
	fontstring:SetText("");
	fontstring:SetPoint("TOP", areaFrame, "TOP", 0, -20);
	fontstring = areaFrame:CreateFontString("MapLibFrameAreaDescription", "OVERLAY");
	fontstring:SetFontObject(SubZoneTextFont);
	fontstring:SetText("");
	fontstring:SetPoint("TOP", "MapLibFrameAreaLabel", "BOTTOM", 0, 0);

	-- Loading!!
	local fr = CreateFrame("Frame", "MapLibFrameLoading", button);
	fr:SetWidth(1); fr:SetHeight(1);
	fr:SetPoint("CENTER", button, "CENTER", 0, 0);
	fr:Hide();
	-- on top of all!
	fr:SetFrameLevel(100);
	fontstring = fr:CreateFontString("MapLibFrameLoadingText", "OVERLAY");
	fontstring:SetFontObject(WorldMapTextFont);
	fontstring:SetText(L["Loading..."]);
	fontstring:SetTextColor(MapLib.colors[1].r, MapLib.colors[1].g, MapLib.colors[1].b);
	fontstring:SetPoint("CENTER", fr, "CENTER", 0, 0);
	fontstring:Show();

	-- Options Frame
	fr = CreateFrame("Frame", "MapLibOptions", MapLibFrame);
	fr:SetWidth(750);
	fr:SetHeight(500);
	fr:SetPoint("CENTER", df, "CENTER", 0, 0);
	fr:SetBackdrop({
		bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", 
		edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", tile = true, tileSize = 32, edgeSize = 32, 
		insets = { left = 11, right = 12, top = 12, bottom = 11 }
	});
	fr:Hide();
	fr:SetFrameLevel(MapLib.FRAMELEVEL_DROPDOWNMENU);
	-- test code: create tabs!
	--[[local moritz = {"General", "MapNotes", "Gathering"}
	for i=1, 3 do
		local frame2 = CreateFrame("Frame", "moritzframe"..i);
		frame2:SetWidth(727);
		frame2:SetHeight(477);
		local texture2 = frame2:CreateTexture(nil, "OVERLAY");
		texture2:SetWidth(727);
		texture2:SetHeight(477);
		texture2:SetPoint("TOPLEFT", frame2, "TOPLEFT", 0, 0);
		texture2:SetTexture(0, i/3, 0);
		MapLib.Options.RegisterMenu(moritz[i], frame2);
	end;]]
	
	texture = fr:CreateTexture("MapLibOptionsHeaderTexture", "ARTWORK");
	texture:SetWidth(256);
	texture:SetHeight(64);
	texture:SetPoint("TOP", fr, "TOP", 0, 12);
	texture:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
	fontstring = fr:CreateFontString("MapLibOptionsHeaderText", "OVERLAY", "GameFontNormal");
	fontstring:SetText(L["Options"]);
--~ 	fontstring:SetTextColor(MapLib.colors[1].r, MapLib.colors[1].g, MapLib.colors[1].b);
	fontstring:SetPoint("TOP", texture, "TOP", 0, -14);
	fontstring:Show();
	
	button = CreateFrame("Button", "MapLibOptionsCancelButton", fr, "UIPanelButtonTemplate");
	button:SetText(L["Cancel"]);
	button:SetWidth(80);
	button:SetHeight(21);
	button:SetPoint("BOTTOMRIGHT", fr, "BOTTOMRIGHT", -25, 19);

	button = CreateFrame("Button", "MapLibOptionsSaveButton", fr, "UIPanelButtonTemplate");
	button:SetText(L["Save"]);
	button:SetWidth(80);
	button:SetHeight(21);
	button:SetPoint("RIGHT", MapLibOptionsCancelButton, "LEFT", -5, 0);	
	
	button = CreateFrame("Button", "MapLibOptionsResetButton", fr, "UIPanelButtonTemplate");
	button:SetText(L["Reset"]);
	button:SetWidth(80);
	button:SetHeight(21);
	button:SetPoint("RIGHT", MapLibOptionsSaveButton, "LEFT", -5, 0);	
	
	button = CreateFrame("Button", "MapLibOptionsDefaultButton", fr, "UIPanelButtonTemplate");
	button:SetText(L["Default"]);
	button:SetWidth(80);
	button:SetHeight(21);
	button:SetPoint("RIGHT", MapLibOptionsResetButton, "LEFT", -5, 0);	

	-- Options Frame open/close button
	local button = CreateFrame("Button", "MapLibOptionsOpenCloseButton", frame);
	button:SetWidth(32);
	button:SetHeight(32);
	button:SetNormalTexture(MapLib.PATH.."\\Artwork\\Button-Options-Up");
	button:SetPushedTexture(MapLib.PATH.."\\Artwork\\Button-Options-Down");
	button:SetDisabledTexture(MapLib.PATH.."\\Artwork\\Button-Options-Disabled");
	button:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight");
	button:SetPoint("TOPLEFT", pg, "TOP", -516, 4);
	button:SetScript("OnClick", function() if (MapLibOptions:IsShown()) then MapLibOptions:Hide(); else MapLib.EventHandler.TriggerEvent("MAPLIB_OPTIONS_RESET"); MapLibOptions:Show(); end; end);
	local texture = button:CreateTexture(nil, "BACKGROUND");
	texture:SetWidth(32);
	texture:SetHeight(32);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\UI-DialogBox-Corner-Mirrored");
	texture:SetPoint("TOPLEFT", button, "TOPLEFT", 4, -4);
	
		-- drop down button (continents);
	MapLib.XML.CreateDropDown("MapLibPOIDropDown", "", -276);
	MapLibPOIDropDownText:SetText(L["POI Options"]);
	MapLib.XML.CreateDropDown("MapLibContinentDropDown", "Continent", -134);
	MapLib.XML.CreateDropDown("MapLibZoneDropDown", "Zone", 8);
	MapLib.XML.CreateDropDown("MapLibInstanceDropDown", "Instance", 150);
	
	fr = CreateFrame("Frame", "MapLibDropDownList", MapLibFrame);
	fr:SetWidth(174);
	fr:SetHeight(44);
	fr:SetPoint("CENTER", frame, "CENTER", 0, 0);
	fr:SetBackdrop({
		bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", 
		edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", tile = true, tileSize = 32, edgeSize = 32, 
		insets = { left = 11, right = 12, top = 12, bottom = 11 }
	});
	fr:Show();
	fr:SetFrameLevel(MapLib.FRAMELEVEL_DROPDOWNMENU);
	
	
	fr = CreateFrame("Frame", "MapLibDropDownSubMenuList", MapLibFrame);
	fr:SetWidth(225);
	fr:SetHeight(44);
	fr:SetPoint("CENTER", frame, "CENTER", 0, 0);
	fr:SetBackdrop({
		bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", 
		edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", tile = true, tileSize = 32, edgeSize = 32, 
		insets = { left = 11, right = 12, top = 12, bottom = 11 }
	});
	fr:Hide();
	fr:SetFrameLevel(MapLib.FRAMELEVEL_DROPDOWNMENU);
	
	-- Create the Tooltip.
	fr = CreateFrame("GameTooltip", "MapLibTooltip", MapLibFrame);
	fr:Hide();
	fr:SetFrameStrata("TOOLTIP");
	fr:SetBackdrop({
		bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", 
		edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, 
		insets = { left = 5, right = 5, top = 5, bottom = 5 }
	});
	fr:SetBackdropBorderColor(MapLib.colors[3].r, MapLib.colors[3].g, MapLib.colors[3].b);
	fr:SetBackdropColor(MapLib.colors[4].r, MapLib.colors[4].g, MapLib.colors[4].b);
	local fs1 = MapLibTooltip:CreateFontString("MapLibTooltipTextLeft1", "ARTWORK", "GameTooltipHeaderText");
	local fs2 = MapLibTooltip:CreateFontString("MapLibTooltipTextRight1", "ARTWORK", "GameTooltipHeaderText");
	fs1:SetPoint("TOPLEFT", fr, "TOPLEFT", 10, -10);
	fs2:SetPoint("RIGHT", fs1, "LEFT", 40, 0);
	fr:AddFontStrings(fs1, fs2);
	for i = 2, 30, 1 do
		fs1 = MapLibTooltip:CreateFontString("MapLibTooltipTextLeft"..i, "ARTWORK", "GameTooltipText");
		fs2 = MapLibTooltip:CreateFontString("MapLibTooltipTextRight"..i, "ARTWORK", "GameTooltipText");
		fs1:SetPoint("TOPLEFT", "MapLibTooltipTextLeft"..(i-1), "BOTTOMLEFT", 0, 0);
		fs2:SetPoint("RIGHT", fs1, "LEFT", 40, 0);
		fr:AddFontStrings(fs1, fs2);
	end;
	
	-- create the multiple POI menu
	fr = CreateFrame("Frame", "MapLibMultiplePOIMenu", MapLibFrame);
	fr:Hide();
	fr:SetFrameStrata("TOOLTIP");
	fr:SetBackdrop({
		bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", 
		edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, 
		insets = { left = 5, right = 5, top = 5, bottom = 5 }
	});
	fr:SetBackdropBorderColor(MapLib.colors[3].r, MapLib.colors[3].g, MapLib.colors[3].b);
	fr:SetBackdropColor(MapLib.colors[4].r, MapLib.colors[4].g, MapLib.colors[4].b);
	fr:SetWidth(160);
	fr:SetHeight(80);
	fr:SetPoint("CENTER", MapLibButton, "CENTER", 0, 0);
	fr:SetFrameLevel(MapLib.FRAMELEVEL_MULTIPLEPOIMENU);
	
	fr = CreateFrame("Frame", "MapLibMultiplePOIMenuHeaderFrame", MapLibMultiplePOIMenu);
	fr:Show();
	fr:SetBackdrop({
		bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", 
		edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, 
		insets = { left = 5, right = 5, top = 5, bottom = 5 }
	});
	fr:SetBackdropBorderColor(MapLib.colors[3].r, MapLib.colors[3].g, MapLib.colors[3].b);
	fr:SetBackdropColor(MapLib.colors[4].r, MapLib.colors[4].g, MapLib.colors[4].b);
	fr:SetWidth(120);
	fr:SetHeight(25);
	fr:SetPoint("TOP", MapLibMultiplePOIMenu, "TOP", 0, 8);
	fr:SetFrameLevel(MapLib.FRAMELEVEL_MULTIPLEPOIMENU+1);
	
	texture = fr:CreateTexture("MapLibMultiplePOIMenuHeaderBG", "ARTWORK");
	texture:SetHeight(16);
	texture:SetWidth(110);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\BG");
	texture:SetPoint("TOP", MapLibMultiplePOIMenuHeaderFrame, "TOP", 0, -5);
	texture:SetVertexColor(MapLib.colors[1].r, MapLib.colors[1].g, MapLib.colors[1].b);

	fontstring = fr:CreateFontString("MapLibMultiplePOIMenuHeader", "OVERLAY", "GameFontHighlightSmall");
	fontstring:SetText(L["Multiple POI"]);
	fontstring:SetJustifyH("CENTER");
	fontstring:SetHeight(16);
	fontstring:SetWidth(110);
	fontstring:SetPoint("LEFT", MapLibMultiplePOIMenuHeaderBG, "LEFT", 0, 1);
	
	-- create normal menu / poi menu
	fr = CreateFrame("Frame", "MapLibMenu", MapLibFrame);
	fr:Hide();
	fr:SetFrameStrata("TOOLTIP");
	fr:SetBackdrop({
		bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", 
		edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, 
		insets = { left = 5, right = 5, top = 5, bottom = 5 }
	});
	fr:SetBackdropBorderColor(MapLib.colors[3].r, MapLib.colors[3].g, MapLib.colors[3].b);
	fr:SetBackdropColor(MapLib.colors[4].r, MapLib.colors[4].g, MapLib.colors[4].b);
	fr:SetWidth(160);
	fr:SetHeight(80);
	fr:SetPoint("CENTER", MapLibButton, "CENTER", 0, 0);
	fr:SetFrameLevel(MapLib.FRAMELEVEL_MENU_AND_TOOLTIP);
	fr:SetScript("OnHide", MapLib.Menu.OnHide);
	
	fr = CreateFrame("Frame", "MapLibMenuHeaderFrame", MapLibMenu);
	fr:Show();
	fr:SetBackdrop({
		bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", 
		edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, 
		insets = { left = 5, right = 5, top = 5, bottom = 5 }
	});
	fr:SetBackdropBorderColor(MapLib.colors[3].r, MapLib.colors[3].g, MapLib.colors[3].b);
	fr:SetBackdropColor(MapLib.colors[4].r, MapLib.colors[4].g, MapLib.colors[4].b);
	fr:SetWidth(120);
	fr:SetHeight(25);
	fr:SetPoint("TOP", MapLibMenu, "TOP", 0, 8);
	fr:SetFrameLevel(MapLib.FRAMELEVEL_MENU_AND_TOOLTIP+1);

	-- empty button to make it possible to scroll in this menu without resetting it
	-- in the 2 row version of multiple poi
	button = CreateFrame("Button", nil, MapLibMenu);
	button:SetWidth(160);
	button:SetHeight(23);
	button:SetFrameLevel(MapLib.FRAMELEVEL_MENU_AND_TOOLTIP);
	button:Show();
	button:SetPoint("TOP", MapLibMenu, "TOP", 0, 0);
	
	texture = fr:CreateTexture("MapLibMenuHeaderBG", "ARTWORK");
	texture:SetHeight(16);
	texture:SetWidth(110);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\BG");
	texture:SetPoint("TOP", MapLibMenuHeaderFrame, "TOP", 0, -5);
	texture:SetVertexColor(MapLib.colors[1].r, MapLib.colors[1].g, MapLib.colors[1].b);

	fontstring = fr:CreateFontString("MapLibMenuHeader", "OVERLAY", "GameFontHighlightSmall");
	fontstring:SetText(L["Menu"]);
	fontstring:SetJustifyH("CENTER");
	fontstring:SetHeight(16);
	fontstring:SetWidth(110);
	fontstring:SetPoint("LEFT", MapLibMenuHeaderBG, "LEFT", 0, 1);
	
	--Create BlockButton
	fr = CreateFrame("Button", "MapLibBlockButton", MapLibFrame);
	fr:Hide();
	fr:SetFrameLevel(MapLib.FRAMELEVEL_BLOCKBUTTON); -- testing only
	fr:SetWidth(992);
	fr:SetHeight(768);
	fr:SetPoint("TOP", pg, "TOP", 0, -32);
	fr:SetScript("OnShow", MapLib.Block.SetGrayscale);
	fr:SetScript("OnHide", MapLib.Block.ResetGrayscale);
	fr:SetScript("OnClick", MapLib.Block.OnClick);
		
	texture = fr:CreateTexture("MapLibBlockButtonTexture", "BACKGROUND");
	texture:Hide();
	texture:SetTexture(0, 0, 0, 0.4);
	texture:SetWidth(1002);
	texture:SetHeight(668);
	texture:SetPoint("TOPLEFT", pg, "TOP", -502, -69);
	
	--Create BlizzardPOI Tooltip
	fr = CreateFrame("Frame", "MapLibBlizzardPOITooltip", MapLibFrame);
	fr:Hide();
	fr:SetFrameStrata("TOOLTIP");
	fr:SetBackdrop({
		bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", 
		edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, 
		insets = { left = 5, right = 5, top = 5, bottom = 5 }
	});
	fr:SetBackdropBorderColor(MapLib.colors[3].r, MapLib.colors[3].g, MapLib.colors[3].b);
	fr:SetBackdropColor(MapLib.colors[4].r, MapLib.colors[4].g, MapLib.colors[4].b);
	fr:SetWidth(160);
	fr:SetHeight(41); -- 25 = one line, 41 = 2 lines
	fr:SetPoint("CENTER", MapLibButton, "CENTER", 0, 0);
	fr:SetFrameLevel(MapLib.FRAMELEVEL_MENU_AND_TOOLTIP);
	
	texture = fr:CreateTexture("MapLibBlizzardPOITooltipBG", "ARTWORK");
	texture:SetHeight(16);
	texture:SetWidth(150);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\BG");
	texture:SetPoint("TOP", MapLibBlizzardPOITooltip, "TOP", 0, -5);
	texture:SetVertexColor(MapLib.colors[1].r, MapLib.colors[1].g, MapLib.colors[1].b);
	
	texture = fr:CreateTexture("MapLibBlizzardPOITooltipIcon", "OVERLAY");
	texture:SetHeight(14);
	texture:SetWidth(14);
	texture:SetPoint("LEFT", MapLibBlizzardPOITooltipBG, "LEFT", 2, 0);
	
	fontstring = fr:CreateFontString("MapLibBlizzardPOITooltipHeader", "OVERLAY", "GameFontHighlightSmall");
	fontstring:SetJustifyH("LEFT");
	fontstring:SetHeight(16);
	fontstring:SetWidth(130);
	fontstring:SetPoint("LEFT", MapLibBlizzardPOITooltipIcon, "RIGHT", 0, 1);
	fontstring = fr:CreateFontString("MapLibBlizzardPOITooltipDescription", "OVERLAY", "GameFontHighlightSmall");
	fontstring:SetText("Description");
	fontstring:SetJustifyH("LEFT");
	fontstring:SetHeight(16);
	fontstring:SetWidth(150);
	fontstring:SetPoint("TOP", MapLibBlizzardPOITooltipBG, "BOTTOM", 0, 2);	
	fontstring = fr:CreateFontString("MapLibBlizzardPOITooltipDescription2", "OVERLAY", "GameFontHighlightSmall");
	fontstring:SetText("Description 2");
	fontstring:SetJustifyH("LEFT");
	fontstring:SetHeight(16);
	fontstring:SetWidth(150);
	fontstring:SetPoint("TOP", MapLibBlizzardPOITooltipDescription, "BOTTOM", 0, 2);
	
	-- Create SideMenu
	fr = CreateFrame("Frame", "MapLibSideMenu", MapLibFrame);
	fr:SetScript("OnShow", MapLib.SideMenu.OnShow);
	fr:SetScript("OnHide", MapLib.SideMenu.OnHide);
	fr:SetHeight(1); fr:SetWidth(1);
	fr:SetPoint("TOPLEFT", pg, "TOPLEFT");
	fr:Hide();
	
	fr = CreateFrame("Frame", "MapLibSideMenuWindowed", MapLibSideMenu);
	fr:SetWidth(384);
	fr:SetHeight(680);
	fr:SetPoint("TOPRIGHT", pg, "TOP", -502, -200);
	-- /script MapLibSideMenuWindowed:SetPoint("TOPRIGHT", MapLibPositioningGuide, "TOP", -510, -63);
	fr:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU);
	fr:Hide();
	
	texture = fr:CreateTexture("MapLibSideMenuBackgroundWindowed1", "BACKGROUND");
	texture:SetHeight(512);
	texture:SetWidth(256);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\SideMenu-Background-Windowed1");
	texture:SetPoint("TOPLEFT", MapLibSideMenuWindowed, "TOPLEFT", 0, 0);
	texture = fr:CreateTexture("MapLibSideMenuBackgroundWindowed2", "BACKGROUND");
	texture:SetHeight(512);
	texture:SetWidth(128);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\SideMenu-Background-Windowed2");
	texture:SetPoint("LEFT", MapLibSideMenuBackgroundWindowed1, "RIGHT", 0, 0);
	
	fr = CreateFrame("Frame", "MapLibSideMenuFullscreen", MapLibSideMenu);
	fr:SetWidth(384);
	fr:SetHeight(680);
	fr:SetPoint("TOPLEFT", pg, "TOP", -510, -63);
	fr:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU);
	
	texture = fr:CreateTexture("MapLibSideMenuBackgroundTop1", "BACKGROUND");
	texture:SetHeight(256);
	texture:SetWidth(256);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\SideMenu-Background-Top1");
	texture:SetPoint("TOPLEFT", fr, "TOPLEFT", 0, 0);
	texture = fr:CreateTexture("MapLibSideMenuBackgroundTop2", "BACKGROUND");
	texture:SetHeight(256);
	texture:SetWidth(128);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\SideMenu-Background-Top2");
	texture:SetPoint("LEFT", MapLibSideMenuBackgroundTop1, "RIGHT", 0, 0);
	texture = fr:CreateTexture("MapLibSideMenuBackgroundBottom1", "BACKGROUND");
	texture:SetHeight(512);
	texture:SetWidth(256);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\SideMenu-Background-Bottom1");
	texture:SetPoint("TOPLEFT", MapLibSideMenuBackgroundTop1, "BOTTOMLEFT", 0, 37);
	texture = fr:CreateTexture("MapLibSideMenuBackgroundBottom2", "BACKGROUND");
	texture:SetHeight(512);
	texture:SetWidth(128);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\SideMenu-Background-Bottom2");
	texture:SetPoint("LEFT", MapLibSideMenuBackgroundBottom1, "RIGHT", 0, 0);
	texture = fr:CreateTexture("MapLibSideMenuMapBorder", "ARTWORK");
	texture:SetHeight(171);
	texture:SetWidth(295);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\SideMenu-Map-Border");
	texture:SetTexCoord(0, 0.576171875, 0, 0.66796875);
	texture:SetPoint("TOP", fr, "TOP", 0, -16);

-- Create 12 tiles!
	texture = fr:CreateTexture("MapLibSideMenuDetailTile1", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", fr, "TOPLEFT", 78, -24);
	texture = fr:CreateTexture("MapLibSideMenuDetailTile2", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile1", "TOPRIGHT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile3", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile2", "TOPRIGHT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile4", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile3", "TOPRIGHT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile5", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile1", "BOTTOMLEFT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile6", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile5", "TOPRIGHT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile7", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile6", "TOPRIGHT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile8", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile7", "TOPRIGHT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile9", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile5", "BOTTOMLEFT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile10", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile9", "TOPRIGHT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile11", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile10", "TOPRIGHT");
	texture = fr:CreateTexture("MapLibSideMenuDetailTile12", "BORDER");
	texture:SetWidth(58);
	texture:SetHeight(58);
	texture:SetPoint("TOPLEFT", "MapLibSideMenuDetailTile11", "TOPRIGHT");
-- create a function for the overlays
-- create a function to update on mapchange or show

	fr = CreateFrame("Button", "MapLibSideMenuBlockButton", MapLibSideMenu);
	fr:SetWidth(MapLib.SIDEMENU_WIDTH);
	fr:SetHeight(668);
	fr:SetPoint("TOPLEFT", pg, "TOP", -502, -69);
	fr:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU);

	button = CreateFrame("Button", "MapLibSideMenuMapOverlayButton", MapLibSideMenuFullscreen);
	button:SetWidth(224);
	button:SetHeight(149);
	button:SetPoint("TOPLEFT", MapLibSideMenuMapBorder, "TOPLEFT", 36, -11);
	button:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU+1);
	button:SetScript("OnMouseUp", MapLib.SideMenu.MapOnMouseUp);
	button:SetScript("OnMouseDown", MapLib.SideMenu.MapOnMouseDown);
	
	texture = button:CreateTexture("MapLibSideMenuMapOverlayTexture", "OVERLAY");
	texture:SetWidth(141);
	texture:SetHeight(149);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\SideMenu-Map-Border");
	texture:SetTexCoord(0.724609375, 1, 0, 0.58203125);
	texture:SetPoint("TOPLEFT", MapLibSideMenuMapOverlayButton, "TOPLEFT", 0, 0);
	
	-- Create SideMenu Open / Close Button
	fr = CreateFrame("Button", "MapLibSideMenuToggleButton", MapLibFrame);
	fr:SetWidth(31);
	fr:SetHeight(31);
	fr:SetPoint("TOPLEFT", pg, "TOP", -510, -85);
	fr:SetFrameLevel(12);
	fr:SetScript("OnClick", MapLib.SideMenu.ToggleButtonOnClick);
	-- Thats the clickable area as a green texture
--	texture = fr:CreateTexture(nil, "OVERLAY");
--	texture:SetWidth(31);
--	texture:SetHeight(31);
--	texture:SetPoint("TOPLEFT", "MapLibSideMenuToggleButton", "TOPLEFT", 0, 0);
--	texture:SetTexture(0, 1, 0);
	texture = fr:CreateTexture("MapLibSideMenuToggleButtonTexture", "ARTWORK");
	texture:SetWidth(64);
	texture:SetHeight(64);
	texture:SetTexture(MapLib.PATH.."\\ARTWORK\\SideMenu-Button-Open-Enabled");
	texture:SetPoint("TOPLEFT", fr, "TOPLEFT", -3, 12);
end

MapLib.XML.CreateMenuButton = function()
	MapLib.NUM_MENUBUTTONS = MapLib.NUM_MENUBUTTONS + 1;
	local name = "MapLibMenuButton"..MapLib.NUM_MENUBUTTONS;
	local frame = CreateFrame("Button", name, MapLibMenu);
	frame:SetWidth(150);
	frame:SetHeight(16);
	frame:SetFrameLevel(MapLib.FRAMELEVEL_MENU_AND_TOOLTIP+1);
	frame:Show();
	if (MapLib.NUM_MENUBUTTONS == 1) then
		frame:SetPoint("TOP", MapLibMenuHeaderFrame, "BOTTOM", 0, 0); -- /script MapLibMultiplePOIMenuButton1:SetPoint("TOP", MapLibMultiplePOIMenu, "TOP", 0, -5);
	else
		frame:SetPoint("TOP", "MapLibMenuButton"..(MapLib.NUM_MENUBUTTONS - 1), "BOTTOM");
	end
	frame:SetScript("OnClick", function() MapLib.Menu.OnClick(arg1) end);
	frame:SetScript("OnEnter", MapLib.Menu.OnEnter);
	frame:SetScript("OnLeave", MapLib.Menu.OnLeave);
	frame:SetID(MapLib.NUM_MENUBUTTONS);

	local texture = frame:CreateTexture(name.."BG", "ARTWORK");
	texture:SetAllPoints(true);
	texture:Show();
	texture:SetAlpha(0.55);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\BG");
	if (mod(MapLib.NUM_MENUBUTTONS, 2) == 0) then
		texture:SetVertexColor(MapLib.colors[2].r, MapLib.colors[2].g, MapLib.colors[2].b);
	else
		texture:SetVertexColor(MapLib.colors[1].r, MapLib.colors[1].g, MapLib.colors[1].b);
	end;

	local fontString = frame:CreateFontString(name.."Text", "OVERLAY", "GameFontHighlightSmall");
	fontString:SetPoint("LEFT", frame, "Left", 1, 1);
	fontString:SetText("Test 1 2 3 Test");
	fontString:SetWidth(148);
	fontString:SetHeight(16);
	fontString:SetJustifyH("LEFT");
end;

MapLib.XML.CreateMultiplePOIMenuButton = function()
	MapLib.NUM_MULTIPLEPOIMENUBUTTONS = MapLib.NUM_MULTIPLEPOIMENUBUTTONS + 1;
	local name = "MapLibMultiplePOIMenuButton"..MapLib.NUM_MULTIPLEPOIMENUBUTTONS;
	local frame = CreateFrame("Button", name, MapLibMultiplePOIMenu);
	frame:SetWidth(150);
	frame:SetHeight(16);
	frame:SetFrameLevel(MapLib.FRAMELEVEL_MULTIPLEPOIMENU+1);
	frame:Show();
	frame:SetScript("OnClick", function() MapLib.MultiplePOIMenu.OnClick(arg1) end);
	frame:RegisterForClicks("LeftButtonUp", "RightButtonUp");
	frame:SetScript("OnEnter", MapLib.MultiplePOIMenu.OnEnter);
	frame:SetScript("OnLeave", MapLib.MultiplePOIMenu.OnLeave);
	frame:SetID(MapLib.NUM_MULTIPLEPOIMENUBUTTONS);

	local texture = frame:CreateTexture(name.."BG", "ARTWORK");
	--texture:SetHeight(16)
	--texture:SetWidth(150);
	texture:SetAllPoints(true);
	texture:Show();
	texture:SetAlpha(0.55);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\BG");
	if (mod(MapLib.NUM_MULTIPLEPOIMENUBUTTONS, 2) == 0) then
		texture:SetVertexColor(MapLib.colors[2].r, MapLib.colors[2].g, MapLib.colors[2].b);
	else
		texture:SetVertexColor(MapLib.colors[1].r, MapLib.colors[1].g, MapLib.colors[1].b);
	end;

	texture = frame:CreateTexture(name.."Icon", "OVERLAY");
	texture:SetWidth(14);
	texture:SetHeight(14);
	texture:Show();
	texture:SetPoint("LEFT", frame, "LEFT", 2, 0);
	texture:SetTexture(MapLib.PATH.."\\Icons\\Instance_Normal");

	local fontString = frame:CreateFontString(name.."Text", "OVERLAY", "GameFontHighlightSmall");
	fontString:SetPoint("LEFT", texture, "RIGHT", 0, 1);
	fontString:SetText("Test 1 2 3");
	fontString:SetWidth(130);
	fontString:SetHeight(16);
	fontString:SetJustifyH("LEFT");

end;

MapLib.XML.CreateDropDown = function(name, titleText, x)
	local frame = CreateFrame("Frame", name, MapLibFrame);
	frame:SetWidth(40);
	frame:SetHeight(32);
	frame:SetPoint("TOP", "MapLibPositioningGuide", "TOP", x, -35);
	frame:Show();
	local leftTexture = frame:CreateTexture(nil, "ARTWORK");
	leftTexture:SetWidth(25);
	leftTexture:SetHeight(64);
	leftTexture:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 17);
	leftTexture:SetTexture("Interface\\Glues\\CharacterCreate\\CharacterCreate-LabelFrame");
	leftTexture:SetTexCoord(0, 0.1953125, 0, 1);
	local middleTexture = frame:CreateTexture(nil, "ARTWORK");
	middleTexture:SetWidth(125);
	middleTexture:SetHeight(64);
	middleTexture:SetPoint("LEFT", leftTexture, "RIGHT", 0, 0);
	middleTexture:SetTexture("Interface\\Glues\\CharacterCreate\\CharacterCreate-LabelFrame");
	middleTexture:SetTexCoord(0.1953125, 0.8046875, 0, 1);
	local rightTexture = frame:CreateTexture(nil, "ARTWORK");
	rightTexture:SetWidth(25);
	rightTexture:SetHeight(64);
	rightTexture:SetPoint("LEFT", middleTexture, "RIGHT", 0, 0);
	rightTexture:SetTexture("Interface\\Glues\\CharacterCreate\\CharacterCreate-LabelFrame");
	rightTexture:SetTexCoord(0.8046875, 1, 0, 1);
	local fontString = frame:CreateFontString(name.."Text", "ARTWORK", "GameFontHighlightSmall");
	fontString:SetJustifyH("RIGHT");
	fontString:SetText("Test");
	fontString:SetWidth(105);
	fontString:SetHeight(16);
	fontString:SetPoint("RIGHT", rightTexture, "RIGHT", -43, 2);
	fontString = frame:CreateFontString(name.."TitleText", "OVERLAY", "GameFontNormalSmall");
	fontString:SetJustifyH("LEFT");
	fontString:SetText(titleText);
	fontString:SetPoint("TOPLEFT", frame, "TOPLEFT", 20, 10);
	button = CreateFrame("Button", name.."Button", frame);
	button:SetWidth(24);
	button:SetHeight(24);
	button:SetPoint("TOPRIGHT", rightTexture, "TOPRIGHT", -16, -18);
	button:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Up");
	button:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Down");
	button:SetDisabledTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Disabled");
	button:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight");
	button:SetScript("OnClick", MapLib.DropDown.OnClick);
end

MapLib.XML.CreateDropDownMenuButton = function()
	MapLib.NUM_DROPDOWNBUTTONS = MapLib.NUM_DROPDOWNBUTTONS + 1;
	local name = "MapLibDropDownButton"..MapLib.NUM_DROPDOWNBUTTONS;
	local frame = CreateFrame("Button", name, MapLibDropDownList);
	frame:SetWidth(150);
	frame:SetHeight(16);
	frame:SetFrameLevel(MapLib.FRAMELEVEL_DROPDOWNMENU+1);
	frame:Show();
	if (MapLib.NUM_DROPDOWNBUTTONS == 1) then
		frame:SetPoint("TOPLEFT", MapLibDropDownList, "TOPLEFT", 12, -14);
	else
		frame:SetPoint("TOP", "MapLibDropDownButton"..(MapLib.NUM_DROPDOWNBUTTONS - 1), "BOTTOM");
	end
	frame:SetScript("OnClick", MapLib.DropDown.MenuOnClick);
	frame:SetScript("OnEnter", MapLib.DropDown.MenuOnEnter);
	frame:SetScript("OnLeave", MapLib.DropDown.MenuOnLeave);
	frame:SetID(MapLib.NUM_DROPDOWNBUTTONS);

	local texture = frame:CreateTexture(name.."Highlight", "BACKGORUND");
	texture:SetAllPoints(true);
	texture:Hide();
	texture:SetBlendMode("ADD");
	texture:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight");
	texture = frame:CreateTexture(name.."Check", "ARTWORK");
	texture:SetWidth(24);
	texture:SetHeight(24);
	texture:Show();
	texture:SetPoint("LEFT", frame, "LEFT", 0, 0);
	texture:SetTexture("Interface\\Buttons\\UI-CheckBox-Check");
	texture = frame:CreateTexture(name.."Icon", "ARTWORK");
	texture:SetWidth(14);
	texture:SetHeight(14);
	texture:Show();
	texture:SetPoint("LEFT", name.."Check", "RIGHT", -1, 0);
	texture:SetTexture(MapLib.PATH.."\\Icons\\Instance_Normal");
	local fontString = frame:CreateFontString(name.."Text", "ARTWORK", "GameFontHighlightSmall");
	fontString:SetPoint("LEFT", texture, "RIGHT", 1, 0);
	fontString:SetText("Test 1 2 3");
	fontString:SetWidth(112);
	fontString:SetHeight(16);
	fontString:SetJustifyH("LEFT");
	frame = CreateFrame("Button", name.."ExpandArrow", getglobal(name));
	frame:SetWidth(16);
	frame:SetHeight(16);
	frame:SetPoint("RIGHT", name, "RIGHT", -3, 0);
	frame:SetNormalTexture("Interface\\ChatFrame\\ChatFrameExpandArrow");
	frame:SetScript("OnEnter", MapLib.DropDown.ExpandArrowOnEnter);
	frame:SetScript("OnLeave", MapLib.DropDown.ExpandArrowOnLeave);
	frame:SetScript("OnClick", MapLib.DropDown.ExpandArrowOnClick);
end

MapLib.XML.CreateDropDownSubMenuButton = function()
	MapLib.NUM_DROPDOWNSUBMENUBUTTONS = MapLib.NUM_DROPDOWNSUBMENUBUTTONS + 1;
	local name = "MapLibDropDownSubMenuButton"..MapLib.NUM_DROPDOWNSUBMENUBUTTONS;
	local frame = CreateFrame("CheckButton", name, MapLibDropDownSubMenuList);
	frame:SetID(MapLib.NUM_DROPDOWNSUBMENUBUTTONS);
	frame:SetWidth(20);
	frame:SetHeight(20);
	if (MapLib.NUM_DROPDOWNSUBMENUBUTTONS == 1) then
		frame:SetPoint("TOPLEFT", MapLibDropDownSubMenuList, "TOPLEFT", 15, -12);
	elseif (mod(MapLib.NUM_DROPDOWNSUBMENUBUTTONS, 5) == 1) then
		frame:SetPoint("TOP", "MapLibDropDownSubMenuButton"..(MapLib.NUM_DROPDOWNSUBMENUBUTTONS-5), "BOTTOM", 0, -5);
	else
		frame:SetPoint("LEFT", "MapLibDropDownSubMenuButton"..(MapLib.NUM_DROPDOWNSUBMENUBUTTONS-1), "RIGHT", 20, 0);
	end;
	frame:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up");
	frame:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down");
	frame:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight");
	frame:SetDisabledCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled");
	frame:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check");
	frame:SetFrameLevel(MapLib.FRAMELEVEL_DROPDOWNMENU+1);
	
	frame:SetScript("OnClick", MapLib.DropDown.SubMenu.OnClick);
	frame:SetScript("OnEnter", MapLib.DropDown.SubMenu.OnEnter);
	frame:SetScript("OnLeave", MapLib.DropDown.SubMenu.OnLeave);
	
	local texture = frame:CreateTexture(name.."Texture", "ARTWORK");
	texture:SetWidth(16);
	texture:SetHeight(16);
	texture:SetPoint("LEFT", frame, "RIGHT", 0, 0);
end;

MapLib.XML.CreatePOI = function()
	MapLib.NUM_POIS = MapLib.NUM_POIS + 1;
	local button = CreateFrame("Button", "MapLibPOI"..MapLib.NUM_POIS, MapLibButton);
	button:SetWidth(16);
	button:SetHeight(16);
	button:RegisterForClicks("LeftButtonUp", "RightButtonUp");
	button:SetScript("OnEnter", MapLib.POI.OnEnter);
	button:SetScript("OnLeave", MapLib.POI.OnLeave);
	button:SetScript("OnClick", function() MapLib.POI.OnClick(arg1) end);

	local texture = button:CreateTexture(button:GetName().."Texture", "ARTWORK");
	texture:SetAllPoints(true);
end;

MapLib.XML.CreateSideMenuButton = function(text, sideMenuFrame, background, activeButtonTexture, inactiveButtonTexture, windowedBackground, windowedActiveButtonTexture, windowedInactiveButtonTexture)
	if (not background) then background = MapLib.PATH.."\\Artwork\\SideMenu-Background-Bottom"; end;
	if (not activeButtonTexture) then activeButtonTexture = MapLib.PATH.."\\Artwork\\SideMenu-Tab-Active"; end;
	if (not inactiveButtonTexture) then inactiveButtonTexture = MapLib.PATH.."\\Artwork\\SideMenu-Tab-InActive"; end;
	if (not windowedBackground) then windowedBackground = MapLib.PATH.."\\Artwork\\SideMenu-Background-Windowed"; end;
	if (not windowedActiveButtonTexture) then windowedActiveButtonTexture = "Interface\\PaperDollInfoFrame\\UI-Character-ActiveTab"; end;
	if (not windowedInactiveButtonTexture) then windowedInactiveButtonTexture = "Interface\\PaperDollInfoFrame\\UI-Character-InActiveTab"; end;
	MapLib.NUM_SIDEMENUBUTTONS = MapLib.NUM_SIDEMENUBUTTONS + 1;
	
	-- Built the Fullscreen button:
	local name = "MapLibSideMenuTabButton"..MapLib.NUM_SIDEMENUBUTTONS;
	-- Create a button
	local button = CreateFrame("Button", name, MapLibSideMenuFullscreen);
	button:SetHeight(32);
	button:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU+1);

	button:SetTextFontObject("GameFontNormalSmall");
	button:SetDisabledFontObject("GameFontHighlightSmall");
	button:SetHighlightFontObject("GameFontHighlightSmall");
	button:SetText(text);
	button:SetHighlightTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight");
	button:SetID(MapLib.NUM_SIDEMENUBUTTONS);
	
	button:SetWidth(button:GetTextWidth()+20);
	
	-- create a texture for left
	local texture = button:CreateTexture(name.."TextureLeft", "BACKGROUND")
	texture:SetTexture(activeButtonTexture);
	texture:SetTexCoord(0, 0.125, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0);
	-- create a texture for right
	texture = button:CreateTexture(name.."TextureRight", "BACKGROUND")
	texture:SetTexture(activeButtonTexture);
	texture:SetTexCoord(0.875, 1, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0, 0);
	-- create a texture for middle anchor to left and right
	texture = button:CreateTexture(name.."TextureMiddle", "BACKGROUND")
	texture:SetTexture(activeButtonTexture);
	texture:SetTexCoord(0.125, 0.875, 0, 1);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", name.."TextureLeft", "TOPRIGHT", 0, 0);
	texture:SetPoint("TOPRIGHT", name.."TextureRight", "TOPLEFT", 0, 0);
	
	-- create a texture for left
	local texture = button:CreateTexture(name.."TextureInActiveLeft", "BACKGROUND")
	texture:SetTexture(inactiveButtonTexture);
	texture:SetTexCoord(0, 0.125, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0);
	-- create a texture for right
	texture = button:CreateTexture(name.."TextureInActiveRight", "BACKGROUND")
	texture:SetTexture(inactiveButtonTexture);
	texture:SetTexCoord(0.875, 1, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0, 0);
	-- create a texture for middle anchor to left and right
	texture = button:CreateTexture(name.."TextureInActiveMiddle", "BACKGROUND")
	texture:SetTexture(inactiveButtonTexture);
	texture:SetTexCoord(0.125, 0.875, 0, 1);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", name.."TextureInActiveLeft", "TOPRIGHT", 0, 0);
	texture:SetPoint("TOPRIGHT", name.."TextureInActiveRight", "TOPLEFT", 0, 0);
	
	-- create a fontstring
	-- anchor button to the fontstring?

	button.sideMenuFrame = sideMenuFrame;
	
	if (MapLib.NUM_SIDEMENUBUTTONS == 1) then
		-- set point relative to the sideMenu
		button:SetPoint("TOPLEFT", MapLibSideMenuFullscreen, "TOPLEFT", 10, -187);
	else
		button:SetPoint("LEFT", "MapLibSideMenuTabButton"..(MapLib.NUM_SIDEMENUBUTTONS-1), "RIGHT", 3, 0);
	end;
	button:SetScript("OnClick", MapLib.SideMenu.TabOnClick);
	
	-- Build the same again for windowed mode:
	local name = "MapLibSideMenuWindowedTabButton"..MapLib.NUM_SIDEMENUBUTTONS;
	-- Create a button
	local button = CreateFrame("Button", name, MapLibSideMenuWindowed);
	button:SetHeight(32);
	button:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU+1);

	button:SetTextFontObject("GameFontNormalSmall");
	button:SetDisabledFontObject("GameFontHighlightSmall");
	button:SetHighlightFontObject("GameFontHighlightSmall");
	button:SetText(text);
	button:SetHighlightTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight");
	button:SetID(MapLib.NUM_SIDEMENUBUTTONS);
	
	button:SetWidth(button:GetTextWidth()+20);
	
	-- create a texture for left
	local texture = button:CreateTexture(name.."TextureLeft", "BACKGROUND")
	texture:SetTexture(windowedActiveButtonTexture);
	texture:SetTexCoord(0, 0.125, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0);
	-- create a texture for right
	texture = button:CreateTexture(name.."TextureRight", "BACKGROUND")
	texture:SetTexture(windowedActiveButtonTexture);
	texture:SetTexCoord(0.875, 1, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0, 0);
	-- create a texture for middle anchor to left and right
	texture = button:CreateTexture(name.."TextureMiddle", "BACKGROUND")
	texture:SetTexture(windowedActiveButtonTexture);
	texture:SetTexCoord(0.125, 0.875, 0, 1);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", name.."TextureLeft", "TOPRIGHT", 0, 0);
	texture:SetPoint("TOPRIGHT", name.."TextureRight", "TOPLEFT", 0, 0);
	
	-- create a texture for left
	local texture = button:CreateTexture(name.."TextureInActiveLeft", "BACKGROUND")
	texture:SetTexture(windowedInactiveButtonTexture);
	texture:SetTexCoord(0, 0.125, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0);
	-- create a texture for right
	texture = button:CreateTexture(name.."TextureInActiveRight", "BACKGROUND")
	texture:SetTexture(windowedInactiveButtonTexture);
	texture:SetTexCoord(0.875, 1, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0, 0);
	-- create a texture for middle anchor to left and right
	texture = button:CreateTexture(name.."TextureInActiveMiddle", "BACKGROUND")
	texture:SetTexture(windowedInactiveButtonTexture);
	texture:SetTexCoord(0.125, 0.875, 0, 1);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", name.."TextureInActiveLeft", "TOPRIGHT", 0, 0);
	texture:SetPoint("TOPRIGHT", name.."TextureInActiveRight", "TOPLEFT", 0, 0);
	
	-- create a fontstring
	-- anchor button to the fontstring?

	button.sideMenuFrame = sideMenuFrame;
	
	if (MapLib.NUM_SIDEMENUBUTTONS == 1) then
		-- set point relative to the sideMenu
		button:SetPoint("TOPLEFT", MapLibSideMenuWindowed, "TOPLEFT", 12, -471);
		MapLib.SideMenu.SetTabToID(1);
	else
		button:SetPoint("LEFT", "MapLibSideMenuWindowedTabButton"..(MapLib.NUM_SIDEMENUBUTTONS-1), "RIGHT", 3, 0);
		MapLib.SideMenu.SetTabToID(MapLib.SideMenu.currentTab);
	end;
	button:SetScript("OnClick", MapLib.SideMenu.TabOnClick);	
	
	sideMenuFrame:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU+1);
	-- this line is probably useless now, and just plain WRONG
--~ 	sideMenuFrame:SetPoint("TOPLEFT", MapLibSideMenuFullscreen, "TOPLEFT", 9, -221);
end;

MapLib.XML.CreateOptionsButton = function(text, optionsFrame, activeButtonTexture, inactiveButtonTexture)
	if (not activeButtonTexture) then activeButtonTexture = "Interface\\PaperDollInfoFrame\\UI-Character-ActiveTab"; end;
	if (not inactiveButtonTexture) then inactiveButtonTexture = "Interface\\PaperDollInfoFrame\\UI-Character-InActiveTab"; end;
	MapLib.NUM_OPTIONSBUTTONS = MapLib.NUM_OPTIONSBUTTONS + 1;
	
	-- Built the Fullscreen button:
	local name = "MapLibOptionsTabButton"..MapLib.NUM_OPTIONSBUTTONS;
	-- button:SetScript("OnClick", MapLib.Options.TabOnClick);
	-- Create a button
	local button = CreateFrame("Button", name, MapLibOptions);
	button:SetHeight(32);
	button:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU+4);

	button:SetTextFontObject("GameFontNormalSmall");
	button:SetDisabledFontObject("GameFontHighlightSmall");
	button:SetHighlightFontObject("GameFontHighlightSmall");
	button:SetText(text);
	button:SetHighlightTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight");
	button:SetID(MapLib.NUM_OPTIONSBUTTONS);
	
	button:SetWidth(button:GetTextWidth()+20);
	
	-- create a texture for left
	local texture = button:CreateTexture(name.."TextureLeft", "BACKGROUND")
	texture:SetTexture(activeButtonTexture);
	texture:SetTexCoord(0, 0.125, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0);
	-- create a texture for right
	texture = button:CreateTexture(name.."TextureRight", "BACKGROUND")
	texture:SetTexture(activeButtonTexture);
	texture:SetTexCoord(0.875, 1, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0, 0);
	-- create a texture for middle anchor to left and right
	texture = button:CreateTexture(name.."TextureMiddle", "BACKGROUND")
	texture:SetTexture(activeButtonTexture);
	texture:SetTexCoord(0.125, 0.875, 0, 1);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", name.."TextureLeft", "TOPRIGHT", 0, 0);
	texture:SetPoint("TOPRIGHT", name.."TextureRight", "TOPLEFT", 0, 0);
	
	-- create a texture for left
	local texture = button:CreateTexture(name.."TextureInActiveLeft", "BACKGROUND")
	texture:SetTexture(inactiveButtonTexture);
	texture:SetTexCoord(0, 0.125, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0);
	-- create a texture for right
	texture = button:CreateTexture(name.."TextureInActiveRight", "BACKGROUND")
	texture:SetTexture(inactiveButtonTexture);
	texture:SetTexCoord(0.875, 1, 0, 1);
	texture:SetWidth(8);
	texture:SetHeight(32);
	texture:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0, 0);
	-- create a texture for middle anchor to left and right
	texture = button:CreateTexture(name.."TextureInActiveMiddle", "BACKGROUND")
	texture:SetTexture(inactiveButtonTexture);
	texture:SetTexCoord(0.125, 0.875, 0, 1);
	texture:SetHeight(32);
	texture:SetPoint("TOPLEFT", name.."TextureInActiveLeft", "TOPRIGHT", 0, 0);
	texture:SetPoint("TOPRIGHT", name.."TextureInActiveRight", "TOPLEFT", 0, 0);
	
	-- create a fontstring
	-- anchor button to the fontstring?

	button.optionsFrame = optionsFrame;
	
	if (MapLib.NUM_OPTIONSBUTTONS == 1) then
		-- set point relative to the sideMenu
		button:SetPoint("TOPLEFT", MapLibOptions, "TOPLEFT", 12, -489);
		MapLib.Options.SetTabToID(1);
	else
		button:SetPoint("LEFT", "MapLibOptionsTabButton"..(MapLib.NUM_OPTIONSBUTTONS-1), "RIGHT", 3, 0);
		MapLib.Options.SetTabToID(MapLib.Options.currentTab);
	end;
	button:SetScript("OnClick", MapLib.Options.TabOnClick);	
	
	optionsFrame:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU+1);
end;

MapLib.XML.CreateMapLibOptionsFrame = function()
	local frame = CreateFrame("Frame", "MapLibOptionsFrame");
	frame:SetWidth(727);
	frame:SetHeight(477);
	
	-- create string "MapLib"
	local fontstring = frame:CreateFontString("MapLibOptionsHeader", "OVERLAY", "GameFontNormal");
	fontstring:SetText(L["MapLib"]);
	fontstring:SetJustifyH("LEFT");
	fontstring:SetHeight(16);
	fontstring:SetWidth(110);
	fontstring:SetPoint("TOPLEFT", frame, "TOPLEFT", 3, -3);	
	-- create Checkbox + string saying replace
	local fr = CreateFrame("CheckButton", "MapLibOptionsFrameCheckButton1", frame);
	fr:SetHeight(32);
	fr:SetWidth(32);
	fr:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up");
	fr:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down");
	fr:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight");
	fr:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check");
	fr:SetDisabledTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled");
	fr:SetPoint("TOPLEFT", fontstring, "BOTTOMLEFT", 0, -4);
	fr:Enable();
	fr:SetFrameLevel(MapLib.FRAMELEVEL_SIDEMENU+2);
	fontstring = fr:CreateFontString("MapLibOptionsFrameCheckButton1Text", "ARTWORK", "GameFontHighlight");
	fontstring:SetText(L["Replace Worldmap"]);
	fontstring:SetJustifyH("LEFT");
	fontstring:SetPoint("LEFT", fr, "RIGHT", 5, 0);	
	
	return frame;
end;